package com.lwl.Algorithmic_data_structure.class06堆排序;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

public class Code01Comparator {

    static class Student {
        String name;
        Integer age;

        public Student(String name, Integer age) {
            this.name = name;
            this.age = age;
        }

        @Override
        public String toString() {
            return "Student{" +
                    "name='" + name + '\'' +
                    ", age=" + age +
                    '}';
        }
    }

    public static void main(String[] args) {
        Student student1 = new Student("a", 13);
        Student student2 = new Student("b", 12);
        Student student3 = new Student("c", 15);
        List<Student> students = Arrays.asList(student1, student2, student3);
        students.sort(new Comparator<Student>() {
            // 返回负数,第一个排在前面
            // 返回正数,第二个排在前面
            @Override
            public int compare(Student o1, Student o2) {
                return o1.age - o2.age;
            }
        });
        students.forEach(System.out::println);
    }

}
